home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 March: Reference Library / Dev.CD Mar OO RLDisk 1.toast / pc / what's new / development kits / hardware / mac os usb ddk 1.4f3 / interfaces / usb.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-19  |  33.5 KB  |  1,302 lines

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    USB 1.4
  7.  
  8. */
  9. #ifndef __USB__
  10. #define __USB__
  11.  
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15.  
  16. #ifndef __NAMEREGISTRY__
  17. #include <NameRegistry.h>
  18. #endif
  19.  
  20. #ifndef __CODEFRAGMENTS__
  21. #include <CodeFragments.h>
  22. #endif
  23.  
  24. #ifndef __DEVICES__
  25. #include <Devices.h>
  26. #endif
  27.  
  28. #ifndef __MACERRORS__
  29. #include <MacErrors.h>
  30. #endif
  31.  
  32.  
  33.  
  34.  
  35. #if PRAGMA_ONCE
  36. #pragma once
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT
  44. #pragma import on
  45. #endif
  46.  
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54.  
  55. /* ************* Constants ************* */
  56.  
  57. enum {
  58.                                                                 /* Flags */
  59.     kUSBTaskTimeFlag            = 1,
  60.     kUSBHubPower                = 2,
  61.     kUSBPowerReset                = 4,
  62.     kUSBHubReaddress            = 8,
  63.     kUSBAddressRequest            = 16,
  64.     kUSBReturnOnException        = 32,
  65.     kUSBNo5SecTimeout            = 64,
  66.     kUSBTimeout                    = 128,
  67.     kUSBNoDataTimeout            = 256,
  68.     kUSBDebugAwareFlag            = 512,
  69.     kUSBResetDescriptorCache    = 1024
  70. };
  71.  
  72. enum {
  73.                                                                 /* Hub messages */
  74.     kUSBHubPortResetRequest        = 1,
  75.     kUSBHubPortSuspendRequest    = 2,
  76.     kUSBHubPortStatusRequest    = 3
  77. };
  78.  
  79. enum {
  80.     kVendorID_AppleComputer        = 0x05AC
  81. };
  82.  
  83. /* ************* types ************* */
  84.  
  85. typedef SInt32                             USBReference;
  86. typedef USBReference                     USBDeviceRef;
  87. typedef USBDeviceRef *                    USBDeviceRefPtr;
  88. typedef USBReference                     USBInterfaceRef;
  89. typedef USBReference                     USBPipeRef;
  90. typedef USBReference                     USBBusRef;
  91. typedef UInt32                             USBPipeState;
  92. typedef UInt32                             USBCount;
  93. typedef UInt32                             USBFlags;
  94. typedef UInt8                             USBRequest;
  95. typedef UInt8                             USBDirection;
  96. typedef UInt8                             USBRqRecipient;
  97. typedef UInt8                             USBRqType;
  98. typedef UInt16                             USBRqIndex;
  99. typedef UInt16                             USBRqValue;
  100.  
  101.  
  102.  
  103. struct usbControlBits {
  104.     UInt8                             BMRequestType;
  105.     UInt8                             BRequest;
  106.     USBRqValue                         WValue;
  107.     USBRqIndex                         WIndex;
  108.     UInt16                             reserved4;
  109. };
  110. typedef struct usbControlBits            usbControlBits;
  111.  
  112. struct USBIsocFrame {
  113.     OSStatus                         frStatus;
  114.     UInt16                             frReqCount;
  115.     UInt16                             frActCount;
  116. };
  117. typedef struct USBIsocFrame                USBIsocFrame;
  118. enum {
  119.     kUSBMaxIsocFrameReqCount    = 1023                            /* maximum size (bytes) of any one Isoc frame*/
  120. };
  121.  
  122.  
  123. struct usbIsocBits {
  124.     USBIsocFrame *                    FrameList;
  125.     UInt32                             NumFrames;
  126. };
  127. typedef struct usbIsocBits                usbIsocBits;
  128.  
  129. struct usbHubBits {
  130.     UInt32                             Request;
  131.     UInt32                             Spare;
  132. };
  133. typedef struct usbHubBits                usbHubBits;
  134. typedef struct USBPB                     USBPB;
  135. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  136.  
  137. union USBVariantBits {
  138.     usbControlBits                     cntl;
  139.     usbIsocBits                     isoc;
  140.     usbHubBits                         hub;
  141. };
  142. typedef union USBVariantBits            USBVariantBits;
  143.  
  144. struct USBPB {
  145.  
  146.     void *                            qlink;
  147.     UInt16                             qType;
  148.     UInt16                             pbLength;
  149.     UInt16                             pbVersion;
  150.     UInt16                             reserved1;
  151.     UInt32                             reserved2;
  152.  
  153.     OSStatus                         usbStatus;
  154.     USBCompletion                     usbCompletion;
  155.     UInt32                             usbRefcon;
  156.  
  157.     USBReference                     usbReference;
  158.  
  159.     void *                            usbBuffer;
  160.     USBCount                         usbReqCount;
  161.     USBCount                         usbActCount;
  162.  
  163.     USBFlags                         usbFlags;
  164.  
  165.     USBVariantBits                     usb;
  166.  
  167.     UInt32                             usbFrame;
  168.  
  169.     UInt8                             usbClassType;
  170.     UInt8                             usbSubclass;
  171.     UInt8                             usbProtocol;
  172.     UInt8                             usbOther;
  173.  
  174.     UInt32                             reserved6;
  175.     UInt16                             reserved7;
  176.     UInt16                             reserved8;
  177.  
  178. };
  179.  
  180.  
  181. typedef USBPB *                            USBPBPtr;
  182. #if !defined(OLDUSBNAMES)
  183. #define OLDUSBNAMES 0
  184. #endif
  185.  
  186. #if OLDUSBNAMES
  187. #define usbBMRequestType  usb.cntl.BMRequestType
  188. #define usbBRequest       usb.cntl.BRequest
  189. #define usbWValue         usb.cntl.WValue
  190. #define usbWIndex         usb.cntl.WIndex
  191. #endif
  192.  
  193. struct uslReq {
  194.     USBDirection                     usbDirection;
  195.     USBRqType                         usbType;
  196.     USBRqRecipient                     usbRecipient;
  197.     USBRequest                         usbRequest;
  198. };
  199. typedef struct uslReq                    uslReq;
  200.  
  201. enum {
  202.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  203.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  204.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  205.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  206. };
  207.  
  208.  
  209.  
  210.  
  211. #define kUSBNoCallBack ((USBCompletion)-1L)
  212.  
  213.  
  214. typedef UInt8                             bcdUSB;
  215. enum {
  216.     kUSBControl                    = 0,
  217.     kUSBIsoc                    = 1,
  218.     kUSBBulk                    = 2,
  219.     kUSBInterrupt                = 3,
  220.     kUSBAnyType                    = 0xFF
  221. };
  222.  
  223. /* endpoint type */
  224. enum {
  225.     kUSBOut                        = 0,
  226.     kUSBIn                        = 1,
  227.     kUSBNone                    = 2,
  228.     kUSBAnyDirn                    = 3
  229. };
  230.  
  231. /*USBDirection*/
  232. enum {
  233.     kUSBStandard                = 0,
  234.     kUSBClass                    = 1,
  235.     kUSBVendor                    = 2
  236. };
  237.  
  238. /*USBRqType*/
  239. enum {
  240.     kUSBDevice                    = 0,
  241.     kUSBInterface                = 1,
  242.     kUSBEndpoint                = 2,
  243.     kUSBOther                    = 3
  244. };
  245.  
  246. /*USBRqRecipient*/
  247. enum {
  248.     kUSBRqGetStatus                = 0,
  249.     kUSBRqClearFeature            = 1,
  250.     kUSBRqReserved1                = 2,
  251.     kUSBRqSetFeature            = 3,
  252.     kUSBRqReserved2                = 4,
  253.     kUSBRqSetAddress            = 5,
  254.     kUSBRqGetDescriptor            = 6,
  255.     kUSBRqSetDescriptor            = 7,
  256.     kUSBRqGetConfig                = 8,
  257.     kUSBRqSetConfig                = 9,
  258.     kUSBRqGetInterface            = 10,
  259.     kUSBRqSetInterface            = 11,
  260.     kUSBRqSyncFrame                = 12
  261. };
  262.  
  263. /*USBRequest*/
  264.  
  265. enum {
  266.     kUSBDeviceDesc                = 1,
  267.     kUSBConfDesc                = 2,
  268.     kUSBStringDesc                = 3,
  269.     kUSBInterfaceDesc            = 4,
  270.     kUSBEndpointDesc            = 5,
  271.     kUSBHIDDesc                    = 0x21,
  272.     kUSBReportDesc                = 0x22,
  273.     kUSBPhysicalDesc            = 0x23,
  274.     kUSBHUBDesc                    = 0x29
  275. };
  276.  
  277. /* descriptorType */
  278.  
  279. enum {
  280.     kUSBFeatureDeviceRemoteWakeup = 1,
  281.     kUSBFeatureEndpointStall    = 0
  282. };
  283.  
  284. /* Feature selectors */
  285. enum {
  286.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  287.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  288.     kUSBStalled                    = 2,                            /* An error occured on the pipe*/
  289.     kUSBSuspended                = 4,                            /* Device is suspended*/
  290.     kUSBNoBandwidth                = 8                                /* (Isoc or Int) Pipe could not be initialised due to bandwidth constraint*/
  291. };
  292.  
  293. enum {
  294.     kUSB100mAAvailable            = 50,
  295.     kUSB500mAAvailable            = 250,
  296.     kUSB100mA                    = 50,
  297.     kUSBAtrBusPowered            = 0x80,
  298.     kUSBAtrSelfPowered            = 0x40,
  299.     kUSBAtrRemoteWakeup            = 0x20
  300. };
  301.  
  302. enum {
  303.     kUSBRel10                    = 0x0100
  304. };
  305.  
  306. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  307. enum {
  308.     kUSBDeviceDescriptorLength    = 0x12,
  309.     kUSBInterfaceDescriptorLength = 0x09,
  310.     kUSBConfigDescriptorLength    = 0x09
  311. };
  312.  
  313.  
  314. struct USBDeviceDescriptor {
  315.     UInt8                             length;
  316.     UInt8                             descType;
  317.     UInt16                             usbRel;
  318.     UInt8                             deviceClass;
  319.     UInt8                             deviceSubClass;
  320.     UInt8                             protocol;
  321.     UInt8                             maxPacketSize;
  322.     UInt16                             vendor;
  323.     UInt16                             product;
  324.     UInt16                             devRel;
  325.     UInt8                             manuIdx;
  326.     UInt8                             prodIdx;
  327.     UInt8                             serialIdx;
  328.     UInt8                             numConf;
  329. };
  330. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  331. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  332. #ifndef OLDCLASSNAMES
  333. #ifndef __cplusplus
  334. #define class deviceClass
  335. #define subClass deviceSubClass
  336. #endif
  337. #endif
  338.  
  339.  
  340.  
  341. struct USBDescriptorHeader {
  342.     UInt8                             length;
  343.     UInt8                             descriptorType;
  344. };
  345. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  346. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  347.  
  348. struct USBConfigurationDescriptor {
  349.     UInt8                             length;
  350.     UInt8                             descriptorType;
  351.     UInt16                             totalLength;
  352.     UInt8                             numInterfaces;
  353.     UInt8                             configValue;
  354.     UInt8                             configStrIndex;
  355.     UInt8                             attributes;
  356.     UInt8                             maxPower;
  357. };
  358. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  359. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  360.  
  361. struct USBInterfaceDescriptor {
  362.     UInt8                             length;
  363.     UInt8                             descriptorType;
  364.     UInt8                             interfaceNumber;
  365.     UInt8                             alternateSetting;
  366.     UInt8                             numEndpoints;
  367.     UInt8                             interfaceClass;
  368.     UInt8                             interfaceSubClass;
  369.     UInt8                             interfaceProtocol;
  370.     UInt8                             interfaceStrIndex;
  371. };
  372. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  373. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  374.  
  375. struct USBEndPointDescriptor {
  376.     UInt8                             length;
  377.     UInt8                             descriptorType;
  378.     UInt8                             endpointAddress;
  379.     UInt8                             attributes;
  380.     UInt16                             maxPacketSize;
  381.     UInt8                             interval;
  382. };
  383. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  384. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  385.  
  386. struct USBHIDDescriptor {
  387.     UInt8                             descLen;
  388.     UInt8                             descType;
  389.     UInt16                             descVersNum;
  390.     UInt8                             hidCountryCode;
  391.     UInt8                             hidNumDescriptors;
  392.     UInt8                             hidDescriptorType;
  393.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  394.     UInt8                             hidDescriptorLengthHi;
  395. };
  396. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  397. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  398.  
  399. struct USBHIDReportDesc {
  400.     UInt8                             hidDescriptorType;
  401.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  402.     UInt8                             hidDescriptorLengthHi;
  403. };
  404. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  405. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  406.  
  407. struct USBHubPortStatus {
  408.     UInt16                             portFlags;                    /* Port status flags */
  409.     UInt16                             portChangeFlags;            /* Port changed flags */
  410. };
  411. typedef struct USBHubPortStatus            USBHubPortStatus;
  412. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  413. /* ********* ProtoTypes *************** */
  414. /* For dealing with endianisms */
  415. #if CALL_NOT_IN_CARBON
  416. EXTERN_API_C( UInt16 )
  417. HostToUSBWord                    (UInt16                 value);
  418.  
  419. EXTERN_API_C( UInt16 )
  420. USBToHostWord                    (UInt16                 value);
  421.  
  422. EXTERN_API_C( UInt32 )
  423. HostToUSBLong                    (UInt32                 value);
  424.  
  425. EXTERN_API_C( UInt32 )
  426. USBToHostLong                    (UInt32                 value);
  427.  
  428. /* Main prototypes */
  429. /* Transfer commands */
  430. EXTERN_API_C( OSStatus )
  431. USBDeviceRequest                (USBPB *                pb);
  432.  
  433. EXTERN_API_C( OSStatus )
  434. USBBulkWrite                    (USBPB *                pb);
  435.  
  436. EXTERN_API_C( OSStatus )
  437. USBBulkRead                        (USBPB *                pb);
  438.  
  439. EXTERN_API_C( OSStatus )
  440. USBIntRead                        (USBPB *                pb);
  441.  
  442. EXTERN_API_C( OSStatus )
  443. USBIntWrite                        (USBPB *                pb);
  444.  
  445. EXTERN_API_C( OSStatus )
  446. USBIsocRead                        (USBPB *                pb);
  447.  
  448. EXTERN_API_C( OSStatus )
  449. USBIsocWrite                    (USBPB *                pb);
  450.  
  451. /* Pipe state control */
  452. EXTERN_API_C( OSStatus )
  453. USBClearPipeStallByReference    (USBPipeRef             ref);
  454.  
  455. EXTERN_API_C( OSStatus )
  456. USBAbortPipeByReference            (USBReference             ref);
  457.  
  458. EXTERN_API_C( OSStatus )
  459. USBResetPipeByReference            (USBReference             ref);
  460.  
  461. EXTERN_API_C( OSStatus )
  462. USBSetPipeIdleByReference        (USBPipeRef             ref);
  463.  
  464. EXTERN_API_C( OSStatus )
  465. USBSetPipeActiveByReference        (USBPipeRef             ref);
  466.  
  467. EXTERN_API_C( OSStatus )
  468. USBClosePipeByReference            (USBPipeRef             ref);
  469.  
  470. EXTERN_API_C( OSStatus )
  471. USBGetPipeStatusByReference        (USBReference             ref,
  472.                                  USBPipeState *            state);
  473.  
  474.  
  475. /* Configuration services */
  476. EXTERN_API_C( OSStatus )
  477. USBFindNextInterface            (USBPB *                pb);
  478.  
  479. EXTERN_API_C( OSStatus )
  480. USBOpenDevice                    (USBPB *                pb);
  481.  
  482. EXTERN_API_C( OSStatus )
  483. USBSetConfiguration                (USBPB *                pb);
  484.  
  485. EXTERN_API_C( OSStatus )
  486. USBNewInterfaceRef                (USBPB *                pb);
  487.  
  488. EXTERN_API_C( OSStatus )
  489. USBDisposeInterfaceRef            (USBPB *                pb);
  490.  
  491. EXTERN_API_C( OSStatus )
  492. USBConfigureInterface            (USBPB *                pb);
  493.  
  494. EXTERN_API_C( OSStatus )
  495. USBFindNextPipe                    (USBPB *                pb);
  496.  
  497. #endif  /* CALL_NOT_IN_CARBON */
  498.  
  499. #if CALL_NOT_IN_CARBON
  500. EXTERN_API_C( OSStatus )
  501. USBSetPipePolicy                (USBPB *                pb);
  502.  
  503. #endif  /* CALL_NOT_IN_CARBON */
  504.  
  505. /* Dealing with descriptors. */
  506. /* Note most of this is temprorary */
  507. #if CALL_NOT_IN_CARBON
  508. EXTERN_API_C( OSStatus )
  509. USBGetConfigurationDescriptor    (USBPB *                pb);
  510.  
  511. EXTERN_API_C( OSStatus )
  512. USBGetFullConfigurationDescriptor (USBPB *                pb);
  513.  
  514. EXTERN_API_C( OSStatus )
  515. USBGetStringDescriptor            (USBPB *                pb);
  516.  
  517. EXTERN_API_C( OSStatus )
  518. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  519.  
  520. EXTERN_API_C( OSStatus )
  521. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  522.  
  523. EXTERN_API_C( OSStatus )
  524. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  525.  
  526.  
  527.  
  528. /* Utility functions */
  529. EXTERN_API_C( OSStatus )
  530. USBResetDevice                    (USBPB *                pb);
  531.  
  532. EXTERN_API_C( OSStatus )
  533. USBPortStatus                    (USBPB *                pb);
  534.  
  535. EXTERN_API_C( OSStatus )
  536. USBSuspendDevice                (USBPB *                pb);
  537.  
  538. EXTERN_API_C( OSStatus )
  539. USBResumeDeviceByReference        (USBReference             refIn);
  540.  
  541. #endif  /* CALL_NOT_IN_CARBON */
  542.  
  543. #if CALL_NOT_IN_CARBON
  544. EXTERN_API_C( OSStatus )
  545. USBGetBandwidthAvailableByReference (USBReference         ref,
  546.                                  UInt32 *                avail);
  547.  
  548. #endif  /* CALL_NOT_IN_CARBON */
  549.  
  550. #if CALL_NOT_IN_CARBON
  551. EXTERN_API_C( OSStatus )
  552. USBGetFrameNumberImmediate        (USBPB *                pb);
  553.  
  554. EXTERN_API_C( OSStatus )
  555. USBDelay                        (USBPB *                pb);
  556.  
  557. EXTERN_API_C( OSStatus )
  558. USBSAbortQueuesByReference        (USBReference             ref);
  559.  
  560. EXTERN_API_C( OSStatus )
  561. USBAllocMem                        (USBPB *                pb);
  562.  
  563. EXTERN_API_C( OSStatus )
  564. USBDeallocMem                    (USBPB *                pb);
  565.  
  566. /* Expert interface functions */
  567. EXTERN_API_C( OSStatus )
  568. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  569.                                  USBDeviceDescriptorPtr  desc,
  570.                                  USBInterfaceDescriptorPtr  interfacePtr,
  571.                                  USBReference             hubRef,
  572.                                  UInt32                 busPowerAvailable);
  573.  
  574. EXTERN_API_C( OSStatus )
  575. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  576.  
  577. EXTERN_API_C( OSStatus )
  578. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  579.                                  USBDeviceDescriptorPtr  desc,
  580.                                  USBReference             hubRef,
  581.                                  UInt32                 port,
  582.                                  UInt32                 busPowerAvailable);
  583.  
  584. EXTERN_API_C( OSStatus )
  585. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  586.  
  587. EXTERN_API_C( OSStatus )
  588. USBExpertStatus                    (USBDeviceRef             ref,
  589.                                  void *                    pointer,
  590.                                  UInt32                 value);
  591.  
  592. EXTERN_API_C( OSStatus )
  593. USBExpertFatalError                (USBDeviceRef             ref,
  594.                                  OSStatus                 status,
  595.                                  void *                    pointer,
  596.                                  UInt32                 value);
  597.  
  598. #endif  /* CALL_NOT_IN_CARBON */
  599.  
  600. #if CALL_NOT_IN_CARBON
  601. EXTERN_API_C( OSStatus )
  602. USBExpertNotify                    (void *                    note);
  603.  
  604. #endif  /* CALL_NOT_IN_CARBON */
  605.  
  606. #if CALL_NOT_IN_CARBON
  607. EXTERN_API_C( OSStatus )
  608. USBExpertStatusLevel            (UInt32                 level,
  609.                                  USBDeviceRef             ref,
  610.                                  StringPtr                 status,
  611.                                  UInt32                 value);
  612.  
  613. EXTERN_API_C( UInt32 )
  614. USBExpertGetStatusLevel            (void);
  615.  
  616. EXTERN_API_C( void )
  617. USBExpertSetStatusLevel            (UInt32                 level);
  618.  
  619.  
  620.  
  621. EXTERN_API_C( OSStatus )
  622. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  623.                                  UInt32                 reserved1,
  624.                                  UInt32                 reserved2,
  625.                                  UInt32                 powerStatus,
  626.                                  UInt32                 busPowerAvailable,
  627.                                  UInt32                 busPowerNeeded);
  628.  
  629. #endif  /* CALL_NOT_IN_CARBON */
  630.  
  631. enum {
  632.     kUSBDevicePower_PowerOK        = 0,
  633.     kUSBDevicePower_BusPowerInsufficient = 1,
  634.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  635.     kUSBDevicePower_SelfPowerInsufficient = 3,
  636.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  637.     kUSBDevicePower_HubPortOk    = 5,
  638.     kUSBDevicePower_HubPortOverCurrent = 6,
  639.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  640.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  641.     kUSBDevicePower_Reserved3    = 9,
  642.     kUSBDevicePower_Reserved4    = 10
  643. };
  644.  
  645.  
  646. /* For hubs only */
  647. #if CALL_NOT_IN_CARBON
  648. EXTERN_API_C( OSStatus )
  649. USBHubAddDevice                    (USBPB *                pb);
  650.  
  651. EXTERN_API_C( OSStatus )
  652. USBHubConfigurePipeZero            (USBPB *                pb);
  653.  
  654. EXTERN_API_C( OSStatus )
  655. USBHubSetAddress                (USBPB *                pb);
  656.  
  657. EXTERN_API_C( OSStatus )
  658. USBHubDeviceRemoved                (USBPB *                pb);
  659.  
  660. EXTERN_API_C( UInt8 )
  661. USBMakeBMRequestType            (UInt8                     direction,
  662.                                  UInt8                     reqtype,
  663.                                  UInt8                     recipient);
  664.  
  665. EXTERN_API_C( OSStatus )
  666. USBControlRequest                (USBPB *                pb);
  667.  
  668. #endif  /* CALL_NOT_IN_CARBON */
  669.  
  670.  
  671. typedef UInt32                             USBLocationID;
  672. enum {
  673.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  674. };
  675.  
  676.  
  677. enum {
  678.     kNoDeviceRef                = -1
  679. };
  680.  
  681. /* Status Level constants*/
  682. /*
  683. Level 1: Fatal errors
  684. Level 2: General errors that may or may not effect operation
  685. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  686. Level 4: Important status messages from the Expert and USL.
  687. Level 5: General status messages from the Expert and USL.
  688. */
  689. enum {
  690.     kUSBStatusLevelFatal        = 1,
  691.     kUSBStatusLevelError        = 2,
  692.     kUSBStatusLevelClient        = 3,
  693.     kUSBStatusLevelGeneral        = 4,
  694.     kUSBStatusLevelVerbose        = 5
  695. };
  696.  
  697. /* Expert Notification Types*/
  698.  
  699. typedef UInt8 USBNotificationType;
  700. enum {
  701.     kNotifyAddDevice            = 0x00,
  702.     kNotifyRemoveDevice            = 0x01,
  703.     kNotifyAddInterface            = 0x02,
  704.     kNotifyRemoveInterface        = 0x03,
  705.     kNotifyGetDeviceDescriptor    = 0x04,
  706.     kNotifyGetInterfaceDescriptor = 0x05,
  707.     kNotifyGetNextDeviceByClass    = 0x06,
  708.     kNotifyGetDriverConnectionID = 0x07,
  709.     kNotifyInstallDeviceNotification = 0x08,
  710.     kNotifyRemoveDeviceNotification = 0x09,
  711.     kNotifyDeviceRefToBusRef    = 0x0A,
  712.     kNotifyDriverNotify            = 0x0C,
  713.     kNotifyParentNotify            = 0x0D,
  714.     kNotifyAnyEvent                = 0xFF,
  715.     kNotifyPowerState            = 0x17,
  716.     kNotifyStatus                = 0x18,
  717.     kNotifyFatalError            = 0x19,
  718.     kNotifyStatusLevel            = 0x20
  719. };
  720.  
  721. typedef USBNotificationType             USBDriverMessage;
  722. /*
  723.    USB Manager wildcard constants for USBGetNextDeviceByClass
  724.    and USBInstallDeviceNotification.
  725. */
  726.  
  727. typedef UInt16 USBManagerWildcard;
  728. enum {
  729.     kUSBAnyClass                = 0xFFFF,
  730.     kUSBAnySubClass                = 0xFFFF,
  731.     kUSBAnyProtocol                = 0xFFFF,
  732.     kUSBAnyVendor                = 0xFFFF,
  733.     kUSBAnyProduct                = 0xFFFF
  734. };
  735.  
  736.  
  737.  
  738.  
  739. struct ExpertNotificationData {
  740.     USBNotificationType             notification;
  741.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  742.     USBDeviceRef *                    deviceRef;
  743.     UInt32                             busPowerAvailable;
  744.     void *                            data;
  745.     UInt32                             info1;
  746.     UInt32                             info2;
  747. };
  748. typedef struct ExpertNotificationData    ExpertNotificationData;
  749. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  750. /* Definition of function pointer passed in ExpertEntryProc*/
  751. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  752. /* Definition of expert's callback installation function*/
  753. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  754. /* Device Notification Callback Routine*/
  755. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  756. /* Device Notification Parameter Block*/
  757.  
  758. struct USBDeviceNotificationParameterBlock {
  759.     UInt16                             pbLength;
  760.     UInt16                             pbVersion;
  761.     USBNotificationType             usbDeviceNotification;
  762.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  763.     USBDeviceRef                     usbDeviceRef;
  764.     UInt16                             usbClass;
  765.     UInt16                             usbSubClass;
  766.     UInt16                             usbProtocol;
  767.     UInt16                             usbVendor;
  768.     UInt16                             usbProduct;
  769.     OSStatus                         result;
  770.     UInt32                             token;
  771.     USBDeviceNotificationCallbackProcPtr  callback;
  772.     UInt32                             refcon;
  773. };
  774. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  775. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  776. /* Definition of USBDriverNotificationCallback Routine*/
  777. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  778. /* Public Functions*/
  779. #if CALL_NOT_IN_CARBON
  780. EXTERN_API_C( UInt32 )
  781. USBGetVersion                    (void);
  782.  
  783. EXTERN_API_C( OSStatus )
  784. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  785.                                  CFragConnectionID *    connID,
  786.                                  UInt16                 theClass,
  787.                                  UInt16                 theSubClass,
  788.                                  UInt16                 theProtocol);
  789.  
  790. EXTERN_API_C( OSStatus )
  791. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  792.                                  USBDeviceDescriptor *    deviceDescriptor,
  793.                                  UInt32                 size);
  794.  
  795. EXTERN_API_C( OSStatus )
  796. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  797.                                  USBInterfaceDescriptor * interfaceDescriptor,
  798.                                  UInt32                 size);
  799.  
  800. EXTERN_API_C( OSStatus )
  801. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  802.                                  CFragConnectionID *    connID);
  803.  
  804. EXTERN_API_C( void )
  805. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  806.  
  807. EXTERN_API_C( OSStatus )
  808. USBRemoveDeviceNotification        (UInt32                 token);
  809.  
  810. EXTERN_API_C( OSStatus )
  811. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  812.                                  USBBusRef *            busRef);
  813.  
  814. EXTERN_API_C( OSStatus )
  815. USBDriverNotify                    (USBReference             reference,
  816.                                  USBDriverMessage         mesg,
  817.                                  UInt32                 refcon,
  818.                                  USBDriverNotificationCallbackPtr  callback);
  819.  
  820. EXTERN_API_C( OSStatus )
  821. USBExpertNotifyParent            (USBReference             reference,
  822.                                  void *                    pointer);
  823.  
  824. EXTERN_API_C( OSStatus )
  825. USBAddDriverForFSSpec            (USBReference             reference,
  826.                                  FSSpec *                fileSpec);
  827.  
  828. #endif  /* CALL_NOT_IN_CARBON */
  829.  
  830. #if CALL_NOT_IN_CARBON
  831. EXTERN_API_C( OSStatus )
  832. USBAddShimFromDisk                (FSSpec *                shimFilePtr);
  833.  
  834. EXTERN_API_C( OSStatus )
  835. USBReferenceToRegEntry            (RegEntryID *            parentEntry,
  836.                                  USBDeviceRef             parentDeviceRef);
  837.  
  838. #endif  /* CALL_NOT_IN_CARBON */
  839.  
  840. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  841. typedef CALLBACK_API_C( void , HIDNotificationProcPtr )(UInt32 refcon, UInt32 reportSize, void *theReport, USBReference theInterfaceRef);
  842. /* HID Install Interrupt prototype*/
  843. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  844. /* HID Poll Device prototype*/
  845. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  846. /* HID Control Device prototype*/
  847. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  848. /* HID Get Device Info prototype*/
  849. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  850. /* HID Enter Polled Mode prototype*/
  851. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  852. /* HID Exit Polled Mode prototype*/
  853. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  854. /* HID Install Notification prototype*/
  855. typedef CALLBACK_API_C( OSStatus , USBHIDInstallNotificationProcPtr )(HIDNotificationProcPtr pNotificationProc, UInt32 refcon);
  856. enum {
  857.     kHIDStandardDispatchVersion    = 0,
  858.     kHIDReservedDispatchVersion    = 1,
  859.     kHIDNotificationDispatchVersion = 2,
  860.     kHIDCurrentDispatchVersion    = 2
  861. };
  862.  
  863.  
  864.  
  865. struct USBHIDRev2DispatchTable {
  866.     UInt32                             hidDispatchVersion;
  867.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  868.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  869.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  870.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  871.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  872.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  873.     USBHIDInstallNotificationProcPtr  pUSBHIDInstallNotification;
  874. };
  875. typedef struct USBHIDRev2DispatchTable    USBHIDRev2DispatchTable;
  876. typedef USBHIDRev2DispatchTable *        USBHIDRev2DispatchTablePtr;
  877.  
  878. struct USBHIDModuleDispatchTable {
  879.     UInt32                             hidDispatchVersion;
  880.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  881.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  882.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  883.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  884.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  885.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  886. };
  887. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  888. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  889. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  890. #if CALL_NOT_IN_CARBON
  891. EXTERN_API_C( OSStatus )
  892. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  893.                                  UInt32                 refcon);
  894.  
  895. EXTERN_API_C( OSStatus )
  896. USBHIDPollDevice                (void);
  897.  
  898. EXTERN_API_C( OSStatus )
  899. USBHIDControlDevice                (UInt32                 theControlSelector,
  900.                                  void *                    theControlData);
  901.  
  902. EXTERN_API_C( OSStatus )
  903. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  904.                                  void *                    theInfo);
  905.  
  906. EXTERN_API_C( OSStatus )
  907. USBHIDEnterPolledMode            (void);
  908.  
  909. EXTERN_API_C( OSStatus )
  910. USBHIDExitPolledMode            (void);
  911.  
  912. EXTERN_API_C( OSStatus )
  913. USBHIDInstallNotification        (HIDNotificationProcPtr  HIDNotificationFunction,
  914.                                  UInt32                 refcon);
  915.  
  916. EXTERN_API_C( void )
  917. HIDNotification                    (UInt32                 devicetype,
  918.                                  UInt8                     NewHIDData[],
  919.                                  UInt8                     OldHIDData[]);
  920.  
  921. #endif  /* CALL_NOT_IN_CARBON */
  922.  
  923. enum {
  924.     kHIDRqGetReport                = 1,
  925.     kHIDRqGetIdle                = 2,
  926.     kHIDRqGetProtocol            = 3,
  927.     kHIDRqSetReport                = 9,
  928.     kHIDRqSetIdle                = 10,
  929.     kHIDRqSetProtocol            = 11
  930. };
  931.  
  932. enum {
  933.     kHIDRtInputReport            = 1,
  934.     kHIDRtOutputReport            = 2,
  935.     kHIDRtFeatureReport            = 3
  936. };
  937.  
  938. enum {
  939.     kHIDBootProtocolValue        = 0,
  940.     kHIDReportProtocolValue        = 1
  941. };
  942.  
  943. enum {
  944.     kHIDKeyboardInterfaceProtocol = 1,
  945.     kHIDMouseInterfaceProtocol    = 2
  946. };
  947.  
  948. enum {
  949.     kHIDSetLEDStateByBits        = 1,
  950.     kHIDSetLEDStateByBitMask    = 1,
  951.     kHIDSetLEDStateByIDNumber    = 2,
  952.     kHIDRemoveInterruptHandler    = 3,
  953.     kHIDEnableDemoMode            = 4,
  954.     kHIDDisableDemoMode            = 5,
  955.     kHIDRemoveNotification        = 0x1000
  956. };
  957.  
  958. enum {
  959.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  960.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  961.     kHIDGetLEDStateByIDNumber    = 2,
  962.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  963.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  964.     kHIDGetInterruptHandler        = 5,
  965.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  966.     kHIDGetInterruptRefcon        = 7,
  967.     kHIDGetVendorID                = 8,
  968.     kHIDGetProductID            = 9
  969. };
  970.  
  971.  
  972. enum {
  973.     kNumLockLED                    = 0,
  974.     kCapsLockLED                = 1,
  975.     kScrollLockLED                = 2,
  976.     kComposeLED                    = 3,
  977.     kKanaLED                    = 4
  978. };
  979.  
  980. enum {
  981.     kNumLockLEDMask                = 1 << kNumLockLED,
  982.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  983.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  984.     kComposeLEDMask                = 1 << kComposeLED,
  985.     kKanaLEDMask                = 1 << kKanaLED
  986. };
  987.  
  988. enum {
  989.     kUSBCapsLockKey                = 0x39,
  990.     kUSBNumLockKey                = 0x53,
  991.     kUSBScrollLockKey            = 0x47
  992. };
  993.  
  994.  
  995. struct USBMouseData {
  996.     UInt16                             buttons;
  997.     SInt16                             XDelta;
  998.     SInt16                             YDelta;
  999. };
  1000. typedef struct USBMouseData                USBMouseData;
  1001. typedef USBMouseData *                    USBMouseDataPtr;
  1002.  
  1003. struct USBKeyboardData {
  1004.     UInt16                             keycount;
  1005.     UInt16                             usbkeycode[32];
  1006. };
  1007. typedef struct USBKeyboardData            USBKeyboardData;
  1008. typedef USBKeyboardData *                USBKeyboardDataPtr;
  1009.  
  1010. union USBHIDData {
  1011.     USBKeyboardData                 kbd;
  1012.     USBMouseData                     mouse;
  1013. };
  1014. typedef union USBHIDData                USBHIDData;
  1015. typedef USBHIDData *                    USBHIDDataPtr;
  1016. #if CALL_NOT_IN_CARBON
  1017. EXTERN_API_C( void )
  1018. StartCompoundClassDriver        (USBDeviceRef             device,
  1019.                                  UInt16                 classID,
  1020.                                  UInt16                 subClass);
  1021.  
  1022. #endif  /* CALL_NOT_IN_CARBON */
  1023.  
  1024. enum {
  1025.     kUSBCompositeClass            = 0,
  1026.     kUSBAudioClass                = 1,
  1027.     kUSBCommClass                = 2,
  1028.     kUSBHIDClass                = 3,
  1029.     kUSBDisplayClass            = 4,
  1030.     kUSBPrintingClass            = 7,
  1031.     kUSBMassStorageClass        = 8,
  1032.     kUSBHubClass                = 9,
  1033.     kUSBDataClass                = 10,
  1034.     kUSBVendorSpecificClass        = 0xFF
  1035. };
  1036.  
  1037. enum {
  1038.     kUSBCompositeSubClass        = 0,
  1039.     kUSBHubSubClass                = 1,
  1040.     kUSBPrinterSubclass            = 1,
  1041.     kUSBVendorSpecificSubClass    = 0xFF
  1042. };
  1043.  
  1044. enum {
  1045.     kUSBHIDInterfaceClass        = 0x03
  1046. };
  1047.  
  1048. enum {
  1049.     kUSBNoInterfaceSubClass        = 0x00,
  1050.     kUSBBootInterfaceSubClass    = 0x01
  1051. };
  1052.  
  1053. enum {
  1054.     kUSBNoInterfaceProtocol        = 0x00,
  1055.     kUSBKeyboardInterfaceProtocol = 0x01,
  1056.     kUSBMouseInterfaceProtocol    = 0x02,
  1057.     kUSBVendorSpecificProtocol    = 0xFF
  1058. };
  1059.  
  1060. enum {
  1061.     kUSBPrinterUnidirectionalProtocol = 0x01,
  1062.     kUSBPrinterBidirectionalProtocol = 0x02
  1063. };
  1064.  
  1065.  
  1066. enum {
  1067.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  1068. };
  1069.  
  1070. enum {
  1071.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1072.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1073.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1074. };
  1075.  
  1076. enum {
  1077.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1078. };
  1079.  
  1080. enum {
  1081.     kInitialUSBDriverDescriptor    = 0
  1082. };
  1083.  
  1084.  
  1085.  
  1086. typedef UInt32                             USBDriverDescVersion;
  1087. /*  Driver Loading Options*/
  1088.  
  1089. typedef UInt32 USBDriverLoadingOptions;
  1090. enum {
  1091.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1092.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1093.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1094.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1095. };
  1096.  
  1097. enum {
  1098.     kClassDriverPluginVersion    = 0x00001100
  1099. };
  1100.  
  1101.  
  1102.  
  1103.  
  1104. struct USBDeviceInfo {
  1105.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1106.     UInt16                             usbProductID;                /* USB Product ID.*/
  1107.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1108.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1109. };
  1110. typedef struct USBDeviceInfo            USBDeviceInfo;
  1111. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1112.  
  1113. struct USBInterfaceInfo {
  1114.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1115.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1116.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1117.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1118.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1119. };
  1120. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1121. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1122.  
  1123. struct USBDriverType {
  1124.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1125.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1126.     UInt8                             usbDriverSubClass;            /* Module type*/
  1127.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1128. };
  1129. typedef struct USBDriverType            USBDriverType;
  1130. typedef USBDriverType *                    USBDriverTypePtr;
  1131.  
  1132. struct USBDriverDescription {
  1133.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1134.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1135.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1136.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1137.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1138.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1139. };
  1140. typedef struct USBDriverDescription        USBDriverDescription;
  1141. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1142. /*
  1143.    Dispatch Table
  1144.    Definition of class driver's HW Validation proc.
  1145. */
  1146. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1147. /*
  1148.    Definition of class driver's device initialization proc.
  1149.    Called if the driver is being loaded for a device
  1150. */
  1151. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1152. /* Definition of class driver's interface initialization proc.*/
  1153. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1154. /* Definition of class driver's finalization proc.*/
  1155. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1156.  
  1157. typedef UInt32 USBDriverNotification;
  1158. enum {
  1159.     kNotifySystemSleepRequest    = 0x00000001,
  1160.     kNotifySystemSleepDemand    = 0x00000002,
  1161.     kNotifySystemSleepWakeUp    = 0x00000003,
  1162.     kNotifySystemSleepRevoke    = 0x00000004,
  1163.     kNotifyHubEnumQuery            = 0x00000006,
  1164.     kNotifyChildMessage            = 0x00000007,
  1165.     kNotifyExpertTerminating    = 0x00000008,
  1166.     kNotifyDriverBeingRemoved    = 0x0000000B,
  1167.     kNotifyAllowROMDriverRemoval = 0x0000000E
  1168. };
  1169.  
  1170. /*
  1171.    Definition of driver's notification proc.      
  1172.    Added refcon for 1.1 version of dispatch table
  1173. */
  1174. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1175.  
  1176. struct USBClassDriverPluginDispatchTable {
  1177.     UInt32                             pluginVersion;
  1178.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1179.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1180.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1181.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1182.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1183. };
  1184. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1185. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1186. /* Shim Defines*/
  1187. enum {
  1188.     kTheUSBShimDescriptionSignature = FOUR_CHAR_CODE('usbs')
  1189. };
  1190.  
  1191.  
  1192. typedef UInt32 USBShimDescVersion;
  1193. enum {
  1194.     kCurrentUSBShimDescVers        = 0x0100
  1195. };
  1196.  
  1197. /*  Shim Loading Options*/
  1198.  
  1199. typedef UInt32 USBShimLoadingOptions;
  1200. enum {
  1201.     kUSBRegisterShimAsSharedLibrary = 0x00000001                /* Driver's VendorID must match Device's VendorID*/
  1202. };
  1203.  
  1204.  
  1205. struct USBShimDescription {
  1206.     OSType                             usbShimDescSignature;        /* Signature field of this structure.*/
  1207.     USBShimDescVersion                 usbShimDescVersion;            /* Version of this data structure.*/
  1208.     USBShimLoadingOptions             usbDriverLoadingOptions;    /* Options for shim loading.*/
  1209.     Str63                             libraryName;                /* For optional shared library registration*/
  1210. };
  1211. typedef struct USBShimDescription        USBShimDescription;
  1212. typedef USBShimDescription *            USBShimDescriptionPtr;
  1213. /* Hub defines*/
  1214.  
  1215. enum {
  1216.     kUSBHubDescriptorType        = 0x29
  1217. };
  1218.  
  1219. enum {
  1220.                                                                 /* Hub features */
  1221.     kUSBHubLocalPowerChangeFeature = 0,
  1222.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1223.     kUSBHubPortConnectionFeature = 0,
  1224.     kUSBHubPortEnableFeature    = 1,
  1225.     kUSBHubPortSuspendFeature    = 2,
  1226.     kUSBHubPortOverCurrentFeature = 3,
  1227.     kUSBHubPortResetFeature        = 4,
  1228.     kUSBHubPortPowerFeature        = 8,
  1229.     kUSBHubPortLowSpeedFeature    = 9,
  1230.     kUSBHubPortConnectionChangeFeature = 16,
  1231.     kUSBHubPortEnableChangeFeature = 17,
  1232.     kUSBHubPortSuspendChangeFeature = 18,
  1233.     kUSBHubPortOverCurrentChangeFeature = 19,
  1234.     kUSBHubPortResetChangeFeature = 20
  1235. };
  1236.  
  1237.  
  1238. enum {
  1239.     kHubPortConnection            = 1,
  1240.     kHubPortEnabled                = 2,
  1241.     kHubPortSuspend                = 4,
  1242.     kHubPortOverCurrent            = 8,
  1243.     kHubPortBeingReset            = 16,
  1244.     kHubPortPower                = 0x0100,
  1245.     kHubPortSpeed                = 0x0200
  1246. };
  1247.  
  1248. enum {
  1249.     kHubLocalPowerStatus        = 1,
  1250.     kHubOverCurrentIndicator    = 2,
  1251.     kHubLocalPowerStatusChange    = 1,
  1252.     kHubOverCurrentIndicatorChange = 2
  1253. };
  1254.  
  1255. enum {
  1256.     off                            = false,
  1257.     on                            = true
  1258. };
  1259.  
  1260.  
  1261.  
  1262. struct hubDescriptor {
  1263.                                                                 /* See usbDoc pg 250?? */
  1264.     UInt8                             dummy;                        /* to align charcteristics */
  1265.  
  1266.     UInt8                             length;
  1267.     UInt8                             hubType;
  1268.     UInt8                             numPorts;
  1269.  
  1270.     UInt16                             characteristics;
  1271.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1272.     UInt8                             hubCurrent;
  1273.  
  1274.                                                                 /* These are received packed, will have to be unpacked */
  1275.     UInt8                             removablePortFlags[8];
  1276.     UInt8                             pwrCtlPortFlags[8];
  1277. };
  1278. typedef struct hubDescriptor            hubDescriptor;
  1279.  
  1280.  
  1281.  
  1282. #if PRAGMA_STRUCT_ALIGN
  1283.     #pragma options align=reset
  1284. #elif PRAGMA_STRUCT_PACKPUSH
  1285.     #pragma pack(pop)
  1286. #elif PRAGMA_STRUCT_PACK
  1287.     #pragma pack()
  1288. #endif
  1289.  
  1290. #ifdef PRAGMA_IMPORT_OFF
  1291. #pragma import off
  1292. #elif PRAGMA_IMPORT
  1293. #pragma import reset
  1294. #endif
  1295.  
  1296. #ifdef __cplusplus
  1297. }
  1298. #endif
  1299.  
  1300. #endif /* __USB__ */
  1301.  
  1302.